﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpectrumAnalyser.Common.WpfValidation;
using System.ComponentModel;
using SpectrumAnalyser.Common.Helpers;

namespace SpectrumAnalyser.Shell.ViewModels
{
    public class CreateItemViewModel : DataErrorInfoBase, IDataErrorInfo
    {
        public string ItemName { get; set; }

        public string Error
        {
            get
            {
                return this[string.Empty];
            }
        }

        public string this[string propertyName]
        {
            get
            {
                string result = string.Empty;
                propertyName = propertyName ?? string.Empty;
                if (propertyName == string.Empty || propertyName == StaticReflection.GetMemberName<CreateItemViewModel>(x => x.ItemName))
                {
                    if (string.IsNullOrEmpty(this.ItemName))
                    {
                        result = "Name cannot be blank!";
                    }
                }

                if (result == string.Empty && ValidationRules.ContainsKey(propertyName))
                {
                    result = ValidationRules[propertyName].Invoke();
                }
                return result;
            }
        }
    }
}
